#include "TelephoneBook.h"
#include "Contacts.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


enum choice
{
    INSERT = 1,
    DELETE,
    FINDN,
    MODIFY,
    PRINT,
    FUZZY,
    BIRNAY,
    BREAK
};

int main()
{
    Telebook *t = InitTelebook();
    int choice = 0;
    // FILE* f = fopen("./通讯录.text","r");
    // if(f == NULL)
    // {
    //     printf("文件打开失败\n");
    //     return -1;
    // }
    // Conts *s = InitContacts();
    // while()
    // {
    //     fread(s,sizeof(s),1,f);
    // }
    GetTxt(t);
    while (1)
    {
        system("clear");
        printf("请选择需要执行的功能1-6:\n");
        Interface(t);
        Save(t);
        scanf("%d", &choice);
        system("clear");
        switch (choice)
        {
            case INSERT:
                InsertTelebook(t);
                break;
            case DELETE:
                void * p = RemoveTelebook(t, IsEqual);
                if(p != NULL)
                    ClearConts(p);
                break;
            case FINDN:
                FindByElement(t, IsEqual);
                break;
            case MODIFY:
                ModifyByElement(t, IsEqual);
                break;
            case PRINT:
                PrintTelebook(t, PrintConts);
                break;
            case FUZZY:
                FuzzyFind(t, IsStr);
                break;
            case BIRNAY:
                BirnayFind(t,Namecmp2);
                break;
            case BREAK:
                ClearTelebook(t,ClearConts);
                return 0;
                break;
            default:
                printf("请输入正确的序号!\n");
                break;
        }
    }
}
